#include"BinarySearchTree.h"

#include <vector>

void test_key()
{
    std::vector<int> a = {8,1,5,6,3,9,2,1,3,4,7};
    key::BSTree<int> bst;
    for(auto e:a)
    {
        bst.insert(e);
    }
    bst.inOrder();

    // cout<<bst.find(-1)<<endl;
    // cout<<bst.find(2)<<endl;

    for(auto e:a)
    {
        bst.erase(e);
        cout<<e<<":";
        bst.inOrder();
    }
    // bst.erase(5);
    // bst.inOrder();
}

void test_key_value()
{
    key_value::BSTree<std::string, int> count_tree;
    std::vector<std::string> s = {"香蕉", "苹果", "苹果", "西瓜",
        "香蕉","苹果", "西瓜"};
    for(auto e:s)
    {   
        key_value::BSTreeNode<std::string, int>* f_node = count_tree.find(e);
        if(!f_node)
        {
            count_tree.insert(e, 1);
        }
        else{
            f_node->_val++;
        }
    }
    count_tree.inOrder();

    key_value::BSTree<std::string, int> copy = count_tree;
    copy.inOrder();

    key_value::BSTree<std::string, int> bst_equa;
    bst_equa = count_tree;
    bst_equa.inOrder();
    bst_equa["香蕉"] = 10086;
    bst_equa.inOrder();
}


int main()
{
    test_key();
    test_key_value();
    return 0;
}

